﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using volva.Models;

namespace volva.Services
{
    public class SearchService
    {
        /// <summary>
        /// This function is used to search wheter it is for videos, stations or other.
        /// </summary>
        /// <param name="query">The search string</param>
        /// <param name="NSFW">Should the function return Not Safe For Work as well?</param>
        /// <returns>A list of objects</returns>
        static public List<Video> SearchVideo(string query, bool NSFW)
        {
            List<Video> SearchVideo = (from s in DataService.ddc.ScheduleItems
                                       where s.airDateTime > DateTime.Now.AddHours(-12) &&
                                            s.airDateTime < DateTime.Now.AddHours(12) &&
                                            (s.Video.name.Contains(query) || s.Video.description.Contains(query))
                                       select s.Video).ToList();
                //List<Video> SearchVideo = (from v in DataService.ddc.Videos
                //                             where v.name.Contains(query) || v.description.Contains(query)
                //                             select v).ToList();

            if(!NSFW)
            {
                List<Video> SearchVideoNSFW = (from v in SearchVideo
                                                 where v.NSFW == false
                                                 select v).ToList();
                return SearchVideoNSFW;
            }
            
            else
            {
                return SearchVideo;
            }
        }
        /// <summary>
        /// This function Searches for a station
        /// </summary>
        /// <param name="query">The search string</param>
        /// <returns>a list of objects</returns>
        static public List<Station> SearchStation(string query)
        {
            List<Station> SearchStation = (from v in DataService.ddc.Stations
                                         where v.name.Contains(query) || v.description.Contains(query)
                                         select v).ToList();
            return SearchStation;
        }
        /// <summary>
        /// This function searches for a Serie
        /// </summary>
        /// <param name="query">the search string</param>
        /// <returns>returns a list of objects</returns>
        static public List<Series> SearchSeries(string query)
        {
            List<Series> SearchSeries = (from v in DataService.ddc.Series
                                         where v.name.Contains(query) || v.description.Contains(query)
                                         select v).ToList();
            return SearchSeries;
        }
    }
}
